package com.pignest.hotel.service;

import java.util.Date;
import java.util.List;

import com.pignest.hotel.beans.TbCloseAccounts;
import com.pignest.hotel.beans.report.CheckoutSummary;
import com.pignest.hotel.dao.ReportDao;
import com.pignest.hotel.definition.InComeItemType;
import com.pignest.hotel.definition.PayMethod;

public class ReportService extends BaseService {

	private ReportDao dao;
	
	/**
	 * 结账汇总
	 * */
	public CheckoutSummary reportCheckoutSummary(Date startTime, Date endTime) {
		CheckoutSummary summary = new CheckoutSummary();
		List<Object> os = dao.checkoutSummaryByConsume(startTime, endTime);
		if (os != null && !os.isEmpty()) {
			for (Object o : os) {
				Object[] m = (Object[])o;
				String key = (String)m[0];
				Number sum = (Number)m[1];
				InComeItemType type = InComeItemType.valueof(key);
				if (type != null) {
					summary.setConsume(type, sum);
				}
			}
		}
		os = dao.checkoutSummaryByPayment(startTime, endTime);
		if (os != null && !os.isEmpty()) {
			for (Object o : os) {
				Object[] m = (Object[])o;
				String key = (String)m[0];
				Long sum = (Long)m[1];
				PayMethod method = PayMethod.valueof(key);
				if (method != null) {
					summary.setPayment(method, sum);
				}
			}
		}
		return summary;
	}
	
	public List<TbCloseAccounts> reportCheckoutDetail(Date startTime, Date endTime) {
		return dao.checkoutDetail(startTime, endTime);
	}
	
	public long reportMemberCharge(Date startTime, Date endTime) {
		return dao.memberCharge(startTime, endTime);
	}
	
	public void setReportDao(ReportDao dao) {
		this.dao = dao;
	}
}
